/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.UserBean;
import dao.UserDAO;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.context.FacesContext;

/**
 *
 * @author amkreuz
 */
@Named(value = "userListController")
@SessionScoped
public class UserListController implements Serializable {

    /**
     * Creates a new instance of UserListController
     */
    public UserListController() {
    }
    
    public ArrayList<UserBean> getUsers1() {
        ArrayList<UserBean> users = null;
        try {
            UserDAO.init();
            UserBean bean = (UserBean) FacesContext.getCurrentInstance().
                    getExternalContext().getSessionMap().get("userBean");
            users = UserDAO.getUsers(bean.getHouseName());
            for (int i = 0; i < users.size(); i++) {
                if (users.get(i).getUserName().equals(bean.getUserName()))
                    users.remove(i);
            }
            UserDAO.terminate();
        } catch (SQLException ex) {
            Logger.getLogger(UserListController.class.getName()).log(Level.SEVERE, null, ex);
        }
         
        return users;
    }
    
        public ArrayList<UserBean> getUsers() {
        ArrayList<UserBean> users = null;
        try {
            UserDAO.init();
            UserBean bean = (UserBean) FacesContext.getCurrentInstance().
                    getExternalContext().getSessionMap().get("userBean");
            users = UserDAO.getUsers(bean.getHouseName());
            UserDAO.terminate();
        } catch (SQLException ex) {
            Logger.getLogger(UserListController.class.getName()).log(Level.SEVERE, null, ex);
        }
         
        return users;
    }
}
